


***************
*** Table 2 ***
***************


clear all

*Set the folder where data are
cd ""

use B2_correct,clear


*drop HH and workers observed only once
drop if honeobsfyr==1
drop if wnyrsp==1

bysort dhcode year: gen counter = _n == 1   // create a dummy variable 1 for first HH obs in a year, 0 otherwise
by dhcode: replace counter = sum(counter)     // sum the 1s and 0s only within HH, hence the first year that first member in HH is observed is 1, the second year is 2 etc
by dhcode: egen hhnyrsp = max(counter)     //  within HH replaces all values with the highest to give the HH number of years in the UHS
label var hhnyrsp "HH total number of years in UHS panel"
tab hhnyrsp 
drop if hhnyrsp==1


xtset dhcode year

*** county specific trends
quiet tab countyid, gen(countytrend)
quiet for num 1/658: replace countytrendX=countytrendX*year

*** city specific trends
quiet tab cityid, gen(citytrend)
quiet for num 1/194: replace citytrendX=citytrendX*year
replace citygovbalgdp=. if citygovbalgdp<-20
gen lncitygovexp=ln(citygovexp)

** tabulate industries because xtivreg2 does not take factor variables
set more off
tab industryH, gen(indH)
tab industryS, gen(indS)
tab occupationH, gen(occH)
tab occupationS, gen(occS)
tab maritstatusH, gen(marH)
tab maritstatusS, gen(marS)
tab educH, gen(edH)
tab educS, gen(edS)
tab educ2H, gen(ed2H)
tab educ2S, gen(ed2S)


*** gen provinceXtime FE since xtivreg does not use factor variables
set more off
egen provxyr = group(provid year)
tab provxyr, gen(pxy)
egen cityxyr = group(cityid year)
tab cityxyr, gen(cxy)

drop if hMWshare==.


*cd "C:\Users\EDAUTOVI\OneDrive\Research\Minimum Wage\Household-China\Yi Data\ResearchDays\Regressions"
*cd "E:\Minimum Wage\Household-China\Yi Data\RegressionsPaper"
cd "D:\Ernest_USB\Minimum Wage\Household-China\Yi Data\RegressionsPaper"


*Controls
global xhh familysize houseown genderH genderS ageH ageS age2H age2S i.educH i.educS i.educ2H i.educ2S wexperH wexperS wexper2H wexper2S migrH migrS migr2H migr2S i.industryH i.industryS i.occupationH i.occupationS i.maritstatusH i.maritstatusS
global xhhiv familysize houseown genderH genderS ageH ageS age2H age2S wexperH wexperS wexper2H wexper2S migrH migrS migr2H migr2S 

*City
global xcity lnrealcitygdp lnrealcitysalary cityunemplrate citypop       
global xcityge lnrealcitygdp lnrealcitysalary cityunemplrate citypop lncitygovexp         
global xyr year2 year3 year4 year5 year6 year7 year8


*drop the first year of the panel
drop if year==2002

set matsize 5000



*** Table 2 ***

xtreg hhreallabinc effrealmw hhrealotherincUHS hhrealhsln $xhhiv $xcity edH* edS* ed2H* ed2S* pxy* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare==0, fe robust cluster(countyid)
est sto m1

xtreg hhreallabinc effrealmw hhrealotherincUHS  hhrealhsln $xhhiv $xcity edH* edS* ed2H* ed2S* pxy* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare>0.25, fe robust cluster(countyid)
est sto m2

xtreg hhreallabinc effrealmw hhrealotherincUHS  hhrealhsln $xhhiv $xcity edH* edS* ed2H* ed2S* pxy* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare>0.5, fe robust cluster(countyid)
est sto m3

xtreg hhreallabinc effrealmw hhrealotherincUHS  hhrealhsln $xhhiv $xcity edH* edS* ed2H* ed2S* pxy* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare>0.75, fe robust cluster(countyid)
est sto m4

xtreg hhrealcons effrealmw $xhhiv $xcity hhrealotherincUHS hhrealhsln edH* edS* ed2H* ed2S* pxy* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare==0, fe robust cluster(countyid)
est sto m5

xtreg hhrealcons effrealmw $xhhiv $xcity hhrealotherincUHS hhrealhsln edH* edS* ed2H* ed2S* pxy* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare>0.25, fe robust cluster(countyid)
est sto m6

xtreg hhrealcons effrealmw $xhhiv $xcity hhrealotherincUHS hhrealhsln edH* edS* ed2H* ed2S* pxy* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare>0.5, fe robust cluster(countyid)
est sto m7

xtreg hhrealcons effrealmw $xhhiv $xcity hhrealotherincUHS hhrealhsln edH* edS* ed2H* ed2S* pxy* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare>0.75, fe robust cluster(countyid)
est sto m8

estout m1 m2 m3 m4 m5 m6 m7 m8 using "Table_2.tex", style(tex) cells(b(fmt(3)) se(star par fmt(3))) delim("&") numbers starlevels(* 0.10 ** 0.05 *** 0.01) ///
collabels( , none) mlabels("$ S=0 $" "$ S>0.25 $" "$ S>0.5 $" "$ S>0.75 $"  "$ S=0 $" "$ S>0.25 $" "$ S>0.5 $" "$ S>0.75 $" ) ///
mgroups("Household Labor Income (First Stage)" "Household Consumption (Reduced Form)", lhs(Dep.var.:) pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span})) ///
stats(N N_clust N_g r2, fmt(0 0 0 3 3) label(Observations "N clusters" "N. households" "Adjusted $R^{2}$")) ///
keep(effrealmw) varlabels(effrealmw "Minimum wage") varwidth(20) modelwidth(10) ///
prehead("\begin{table}[tbhp] \centering \resizebox{\textwidth}{!} { \begin{tabular}{l*{8}{c}}" \hline) posthead(\hline \\) ///
prefoot( \\ City-level controls & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes  \\ HH FE & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes  ///
\\ County Trend & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes  \\  Prov $\times$ year FE & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes  \\ ) postfoot( \hline "\end{tabular} } \end{table} ") replace





*** Table 3 ***

set more off
est clear 
xtivreg2 hhrealcons (hhreallabinc = effrealmw) hhrealotherincUHS hhrealhsln $xhhiv $xcity edH* edS* ed2H* ed2S* pxy* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare==0, fe robust cluster(countyid)
est sto m1
gen S0_sample_2sls = e(sample)
*Warning - singleton groups detected.  2579 observation(s) not used.


xtivreg2 hhrealcons (hhreallabinc = effrealmw) hhrealotherincUHS hhrealhsln $xhhiv $xcity edH* edS* ed2H* ed2S* pxy* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare>0.25, fe robust cluster(countyid)
est sto m2
gen S25_sample_2sls = e(sample)

xtivreg2 hhrealcons (hhreallabinc = effrealmw) hhrealotherincUHS hhrealhsln $xhhiv $xcity edH* edS* ed2H* ed2S* pxy* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare>0.5, fe robust cluster(countyid)
est sto m3
gen S5_sample_2sls = e(sample)

xtivreg2 hhrealcons (hhreallabinc = effrealmw) hhrealotherincUHS hhrealhsln $xhhiv $xcity edH* edS* ed2H* ed2S* pxy* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare>0.75, fe robust cluster(countyid) 
est sto m4
gen S75_sample_2sls = e(sample)


estout m1 m2 m3 m4 using "Table_3.tex", style(tex) cells(b(fmt(3)) se(star par fmt(3))) delim("&") numbers starlevels(* 0.10 ** 0.05 *** 0.01) ///
collabels( , none) mlabels( "$ S=0 $" "$ S>0.25 $" "$ S>0.5 $" "$ S>0.75 $" ) ///
mgroups("Labor Income" , lhs(Dep.var.: \\ HH real Consumption (RMB)) pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span})) ///
stats(N N_clust N_g r2 idp, fmt(0 0 0 3 3) label(Observations "N clusters" "N households" "Adjusted $R^{2}$" "Weak instr. (pval)")) ///
keep(hhreallabinc) varlabels(hhreallabinc "HH Labor Income") varwidth(20) modelwidth(10) ///
prehead("\begin{table}[tbhp] \centering \resizebox{\textwidth}{!} { \begin{tabular}{l*{4}{c}}" \hline) posthead(\hline \\) ///
prefoot( \\ City-level controls & Yes & Yes & Yes & Yes  \\ Household FE & Yes & Yes & Yes & Yes    ///
\\ Prov $\times$ year FE & Yes & Yes & Yes & Yes  \\ County trends & Yes & Yes & Yes & Yes \\ \hline) postfoot( \hline "\end{tabular} } \end{table} ") replace




*** WEAKIV TEST ***
set more off
est clear 
xtivreg2 hhrealcons (hhreallabinc = effrealmw) hhrealotherincUHS hhrealhsln $xhhiv $xcity edH* edS* ed2H* ed2S* pxy* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare==0, fe robust cluster(countyid)
weakiv

xtivreg2 hhrealcons (hhreallabinc = effrealmw) hhrealotherincUHS hhrealhsln $xhhiv $xcity edH* edS* ed2H* ed2S* pxy* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare>0.25, fe robust cluster(countyid)
weakiv

xtivreg2 hhrealcons (hhreallabinc = effrealmw) hhrealotherincUHS hhrealhsln $xhhiv $xcity edH* edS* ed2H* ed2S* pxy* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare>0.5, fe robust cluster(countyid)
weakiv

xtivreg2 hhrealcons (hhreallabinc = effrealmw) hhrealotherincUHS hhrealhsln $xhhiv $xcity edH* edS* ed2H* ed2S* pxy* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare>0.75, fe robust cluster(countyid) 
weakiv




